package com.leen.aspect.permiss;


import com.leen.aspect.annon.RequiredPermission;
import com.leen.exception.AccessDeniedException;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

/**
 * 自定义权限增强
 * @author wy
 */
@Component
@Aspect
public class RequiredPermissionAspect {

    @Pointcut(value = "@annotation(com.leen.aspect.annon.RequiredPermission) ")
    private void permissionExpress(){
    }


    //前置增强
    @Before(value = "permissionExpress() && @annotation(requiredPermission)")
    public void checkPermission(RequiredPermission requiredPermission){
          //检查检查
        Authorization authorization=AuthorizationFactory.createAuthorization(requiredPermission);
        boolean result=authorization.checkPermission();


        if(!result){
            throw new AccessDeniedException();
        }
    }




}
